package com.course.api.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.course.api.config.Result.Result;
import com.course.api.config.Result.Results;
import com.course.api.entity.CommentThumbs;
import com.course.api.service.Impl.CommentThumbsImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/commentThumbs")
public class CommentThumbsController {

    @Autowired
    CommentThumbsImpl commentThumbsService;

    /**
     * 获取用户点赞的帖子
     * @param userId
     * @return
     */
    @GetMapping("/getLikeComments")
    public Result getLikeComments(@RequestParam Long userId) {
        return Results.success(commentThumbsService.list(new QueryWrapper<CommentThumbs>().eq("user_id", userId)));
    }

    /**
     * 点赞
     * @param commentThumbs
     * @return
     */
    @PostMapping("/giveThumbs")
    public Result giveThumbs(@RequestBody CommentThumbs commentThumbs) {
        commentThumbsService.addThumbs(commentThumbs);
        return Results.success();
    }

    /**
     * 取消点赞
     * @param id
     * @return
     */
    @DeleteMapping("/cancel/{id}")
    public Result cancel(@PathVariable(value = "id") Long id) {
        commentThumbsService.cancelThumbs(id);
        return Results.success();
    }
}
